//
//  GHDemoViewController.swift
//  GHWeibo
//
//  Created by LGH on 2017/8/4.
//  Copyright © 2017年 LGH. All rights reserved.
//

import UIKit

class GHDemoViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.backgroundColor = UIColor.darkGray

        let title = "第\(navigationController?.childViewControllers.count ?? 0)个"
        self.title = title
        
        setupUI()

    }
    
    func setupUI() {

        self.navigationItem.rightBarButtonItem = UIBarButtonItem(titile: "下一个", target: self, action: #selector(showNext))
        var backBtnTitle = "返回"
        if navigationController?.childViewControllers.count == 2 {
            
            backBtnTitle = navigationController?.childViewControllers.first?.title ?? "返回"
            
        }
        
        let barBtn = UIBarButtonItem(titile: backBtnTitle, imageName: "navigationbar_back_withtext", highlightedImageName: "navigationbar_back_withtext_highlighted", target: self, action: #selector(backToPopVC))
        self.navigationItem.leftBarButtonItem = barBtn
        
        
    }
    
    func showNext(){
        
        let vc = GHDemoViewController()
        
        navigationController?.pushViewController(vc, animated: true)
    }
    
    func backToPopVC() {
        
        navigationController?.popViewController(animated: true)
        
    }
}
